<template>
  <div class="container">
    <!-- 面包屑导航 -->
    <div class="breadcrumb">
      <el-breadcrumb separator="">
        <el-breadcrumb-item
          ><div class="div1">基本配置</div></el-breadcrumb-item
        >
        <el-breadcrumb-item
          ><div class="div2">客户黑名单</div></el-breadcrumb-item
        >
      </el-breadcrumb>
    </div>
    <!-- 面包屑导航 teamManage -->
    <!-- 黑名单 -->
    <div class="content">
      <h2>客户黑名单</h2>
      <h3>数据筛选</h3>
      <div>
        <el-form :inline="true" id="search" class="search-form" size="small">
          <el-form-item label="客户姓名">
            <el-input
              v-model="search.customerName"
              placeholder="请输入客户姓名"
              clearable
            ></el-input>
          </el-form-item>
          <el-form-item label="客户电话">
            <el-input
              v-model="search.customerPhone"
              placeholder="请输入客户电话"
            ></el-input>
          </el-form-item>
          <el-form-item label="入线方式">
            <el-select
              v-model="search.userDitch"
              placeholder="请选择入线方式"
              clearable
            >
              <el-option
                v-for="item in userDitchList"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              >
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="跟进客服">
            <el-select
              v-model="search.customerServiceUserId"
              placeholder="请选择跟进客服"
              clearable
              filterable
            >
              <el-option
                v-for="item in salesAuthorityList"
                :key="item.id"
                :label="item.reallyName"
                :value="item.id"
              >
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="类型">
            <el-select
              v-model="search.payType"
              placeholder="请选择类型"
              clearable
            >
              <el-option
                v-for="item in dictionaries.customer_channel_pay_type"
                :key="item.dictId"
                :label="item.dictName"
                :value="item.dictId"
              >
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="部门">
            <el-cascader
              v-model="search.modelOrgCode"
              :options="orgCodeList"
              :props="{
                checkStrictly: true,
                label: 'orgName',
                value: 'orgCode',
                children: 'children',
              }"
              clearable
              filterable
            ></el-cascader>
          </el-form-item>
          <el-form-item label="创建时间">
            <el-date-picker
              v-model="date"
              type="daterange"
              unlink-panels
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              format="yyyy-MM-dd"
              value-format="yyyy-MM-dd"
              @change="onChangeDate"
            >
            </el-date-picker>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="fetchData('search')"
              >查询</el-button
            >
            <el-button
              type="primary"
              plain
              @click="fetchData('reset')"
              >重置</el-button
            ></el-form-item
          >
        </el-form>
      </div>
    </div>
    <div class="content">
      <h3>客户黑名单列表</h3>
      <!-- <div>{{ parArray.indexOf("authorityAdd") == 1 }}{{ parArray }}</div> -->
      <lb-table
      v-horizontal-scroll='always'
        :column="column"
        :data="list"
        pagination
        :total="page.totalNum"
        layout="total, sizes, prev, pager, next, jumper"
        :page-sizes="[5, 10, 20, 30, 50]"
        :current-page.sync="page.currentPage"
        :page-size="page.pageSize"
        @size-change="handleSizeChange"
        @p-current-change="handleCurrentChange"
      >
      </lb-table>
    </div>
    <!-- 管理客户等级 -->
  </div>
</template>

<script>
// import { FormItem } from 'element-ui';
import LbTable from '../../components/lb-table/lb-table'
export default {
  name: 'role',
  components: { LbTable },
  data () {
    return {
      date: '',
      search: {
        customerName: '', // 	否 	string 	客户姓名
        customerPhone: '', // 	否 	string 	客户电话
        userDitch: '', // 	否 	int 	入栈方式、渠道（数据来源【入线渠道设定】）
        customerServiceUserId: '', // 	否 	int 	跟进客服
        payType: '', // 	否 	string 	类型（字典分组：customer_channel_pay_type）
        orgCode: '', // 	否 	string 	部门编码
        modelOrgCode: [], // 	否 	string 	部门编码
        createdTimeStart: '', // 	否 	string 	创建时间-开始时间
        createdTimeEnd: '' // 	否 	string 	创建时间-结束时间
      },
      list: [], // 列表
      column: [
        { label: '平台', prop: 'platformName', width: '120' },
        { label: '渠道', prop: 'channelName', width: '120' },
        { label: '客户姓名', prop: 'customerName', width: '120' },
        { label: '客户电话', prop: 'customerPhone', width: '120' },
        { label: '订单数', prop: 'orderCount', width: '100' },
        { label: '部门', prop: 'orgName', width: '165' },
        { label: '跟进客服', prop: 'customerServiceName' },
        { label: '类型', prop: 'payTypeLabel', width: '120' },
        { label: '操作人', prop: 'createdByName' },
        { label: '创建时间', prop: 'createdTime', width: '200' },
        { label: '分配时间', prop: 'assignTime', width: '200' },
        {
          label: '操作',
          width: '165',
          fixed: 'right',
          render: (h, scope) => {
            return (
              <div>
                <el-link size='mini' type='primary' onClick={() => { this.onDetail(scope.row, scope.$index) }}>查看</el-link>
                <el-link size='mini' type='primary' onClick={() => { this.onRemove(scope.row, scope.$index) }}>移出黑名单</el-link>
              </div>
            )
          }
        }],
      page: { pageNo: 1, pageSize: 10, totalNum: 0, currentPage: 1 },
      dictionaries: { // 字典数据
        customer_channel_pay_type: [] // 类型
      },
      userDitchList: [], // 入栈方式、渠道 列表
      salesAuthorityList: [], // 跟进客服列表
      orgCodeList: [], // 部门列表
      parArray: [] // 按钮权限
    }
  },
  created () {
    this.fetchData()
    // 获取字典值
    for (const type in this.dictionaries) { this.getDictionaries(type) }

    // 渠道列表
    this.getSelectCustomerditch()

    // 跟进客服列表
    this.getSalesAuthority()

    // 部门列表
    this.getOrgTreeList()
  },
  /*
  watch: {
    permissionFilterText (val) {
      this.$refs.tree.filter(val);
    }
  },
  */
  methods: {
    fetchData (type) {
      if (type == 'reset') {
        this.search = {
          customerName: '', // 	否 	string 	客户姓名
          customerPhone: '', // 	否 	string 	客户电话
          userDitch: '', // 	否 	int 	入栈方式、渠道（数据来源【入线渠道设定】）
          customerServiceUserId: '', // 	否 	int 	跟进客服
          payType: '', // 	否 	string 	类型（字典分组：customer_channel_pay_type）
          orgCode: '', // 	否 	string 	部门编码
          createdTimeStart: '', // 	否 	string 	创建时间-开始时间
          createdTimeEnd: '' // 	否 	string 	创建时间-结束时间
        }
        this.date = ''
        this.page.pageNo = 1
        this.page.pageSize = 10
      }
      let params = {
        pageNo: this.page.pageNo,
        pageSize: this.page.pageSize
      }
      if (type == 'search') {
        // const search = this.search
        params = Object.assign(params, this.search)
        if (this.search.modelOrgCode) {
          params.orgCode = this.search.modelOrgCode[this.search.modelOrgCode.length - 1]
        }
        // 去除字符串 前后 空格
        for (const item in params) { if (typeof params[item] === 'string') { params[item] = params[item].trim() } }
      }
      console.log(params)
      this.$api.blackListPageList(params).then((res) => {
        this.list = res.data.list
        this.page.totalNum = res.data.totalNum
      }).catch((err) => {
        console.log(err)
      })
    },
    handleCurrentChange (currentChange) {
      this.page.pageNo = currentChange
      this.fetchData()
    },
    handleSizeChange (sizeChange) {
      this.page.pageSize = sizeChange
      this.fetchData()
    },
    getButtonTreeDto () {
      // 获取权限设定
      this.limits = JSON.parse(sessionStorage.getItem('limit'))
      const params = this.limits.buttonTreeDto.filter(
        (item) => item.menuCode === 'jurisdictionCode'
      )
      params[0].buttonList.forEach((item) => {
        this.parArray.push(item.code)
      })
      // console.log(this.parArray)
    },
    // 获取字典数据
    getDictionaries (type) {
      if (type && this.dictionaries[type].length > 0) { return }
      const params = { groupId: type }
      this.$api.dictionaries(params).then((res) => {
        this.dictionaries[type] = res.data
      }).catch((err) => {
        console.log(err)
      })
    },

    // 渠道列表
    getSelectCustomerditch (type) {
      this.$api.selectCustomerditch().then((res) => {
        this.userDitchList = res.data
      }).catch((err) => {
        console.log(err)
      })
    },

    // 跟进客服列表
    getSalesAuthority (type) {
      this.$api.salesAuthority().then((res) => {
        this.salesAuthorityList = res.data
      }).catch((err) => {
        console.log(err)
      })
    },
    // 部门列表
    getOrgTreeList (type) {
      const params = { request: { orgName: '', orgType: '' }, version: '' }
      this.$api.orgTreeList(params).then((res) => {
        this.orgCodeList = res.data
      }).catch((err) => {
        console.log(err)
      })
    },
    // 修改时间
    onChangeDate (e) {
      this.search.createdTimeStart = e[0]
      this.search.createdTimeEnd = e[1]
    },
    // 黑名单 - 详情
    onDetail (row) {
      console.log(row)
      this.$router.push({
        name: 'customerInformation',
        query: {
          id: row.id,
          navName: 1
        }
      })
    },
    // 移出黑名单
    onRemove (row) {
      this.$confirm(`是否将【${row.customerName}】移出黑名单？`, '移动出黑名单提示')
        .then(_ => {
          const params = { id: row.id }
          this.$api.removeFromBlackList(params).then((res) => {
            if (res.code === 0) {
              this.customerOrderStatities = res.data
              this.$message({ type: 'success', message: '操作成功!' })
              this.fetchData()
            }
          }).catch((err) => {
            console.log(err)
          })
          // done();
        })
        .catch(_ => {
          this.$message({ type: 'info', message: '取消操作!' })
        })
    }
  }
}
</script>

<style scoped lang="scss">
.div1 {
  margin-left: -16px;
  background: url(../../assets/breadcrumb2.png);
  width: 120px;
  height: 30px;
  text-align: center;
  line-height: 30px;
  color: #2d7edf;
}
.div2 {
  margin-left: -16px;
  background: url(../../assets/breadcrumb1.png);
  width: 120px;
  height: 30px;
  text-align: center;
  line-height: 30px;
  color: #fff;
}
.div3 {
  margin-left: -8px;
  background: url(../../assets/breadcrumb3.png);
  width: 120px;
  height: 30px;
  text-align: center;
  line-height: 30px;
  color: #2d7edf;
}
.search-form {
  display: flex;
  flex-wrap: wrap;
  .el-form-item {
    width: 100%;
    max-width: 303px;
    min-width: 299px;
    /deep/.el-form-item__label{
      width: 70px;
    }
    /deep/.el-form-item__content {
      width: calc(100% - 70px);
      .el-select, .el-date-editor, .el-cascader {
        width: 100%;
      }
    }
  }
}

.content {
  margin-bottom: 20px;
  padding: 20px;
  background-color: #ffffff;
  h3 {
    position: relative;
    margin-bottom: 20px;
    //padding-left: 10px;
    font-weight: 400;
    font-size: 18px;
    /*
    &:before {
      position: absolute;
      top: 5px;
      left: 0;
      display: inline-block;
      content: "";
      width: 3px;
      height: 20px;
      background-color: #2d7edf;
    }
    */
  }
  .el-button {
    margin-bottom: 10px;
  }
  .el-badge {
    margin-left: 10px;
  }
}
.roleList {
  border: 1px solid #f0f3fd;
  border-radius: 5px;
  .title {
    color: #333333;
    line-height: 40px;
    padding: 0 10px;
    background-color: #f0f3fd;
    .el-badge {
      margin-top: 10px;
      margin-left: 10px;
    }
  }
  .list {
    padding: 20px;
    .el-tag {
      border: 0;
      margin-right: 10px;
      margin-bottom: 10px;
    }
  }
}
.dialog-content {
  // min-height: 210px;
  .el-tree {
    max-height: 300px;
    overflow: auto;
  }
  .el-radio {
    // display: block;
    // margin: 8px 0;
  }
}
</style>
<style lang="scss">
.content {
  .el-link {
    margin: 0 5px;
  }
  h4 {
    padding-top: 10px;
    border-top: 1px solid #bbbbbb;
  }
}
/deep/.el-scrollbar{
  height:10px;
}
/deep/.el-scrollbar__bar.is-horizontal{
  height: 9px;

}
</style>
